﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MoreEPG.Data;
using System.Windows.Threading;
using MoreEPG.Model;

namespace MoreEPG.DataAccess
{
    public class Datas
    {
        private IData _myData;
        private MCData _myMCData;

        public Datas()
        {
            
        }

        public Datas(Dispatcher UiDispatcher, Delegate ProgressDelegate)
        {
            switch (Properties.Settings.Default.DBSource)
            {
                case MoreEPG.Helper.DataSource.ClickFinder:
                    this._myData = new ClickFinderData();
                    break;
                case MoreEPG.Helper.DataSource.OnView:
                    this._myData = new OnViewData();
                    break;
                case MoreEPG.Helper.DataSource.Xmltv:
                    this._myData = new XmltvData();
                    break;
                case MoreEPG.Helper.DataSource.None:
                    throw new ApplicationException("No DB Source is Set!");
                default:
                    throw new ApplicationException("No DB Source is Set!");
            }
            this._myData.UiDispatcher = UiDispatcher;
            this._myData.ProgressDelegate = ProgressDelegate;
            this._myMCData = new MCData(UiDispatcher, ProgressDelegate);
        }

        public void UpdateSource()
        {
            this._myData.UpdateSource();
        }

        public void FillDatas()
        {
            this._myData.FillDataSet();
        }

        public void FillCollections()
        {
            this._myMCData.FillCollections();
            this._myData.MCImages = this._myMCData.MCImages;
            this._myData.MCPersons = this._myMCData.MCPersons;
            this._myData.MCPrograms = this._myMCData.MCPrograms;
            
            this._myData.FillCollections();
        }

        public ResultCollections Results
        {
            get
            {
                return this._myData.Results;
            }
        }


        public TVChannelCollection GetTVProgramms()
        {
            return this._myData.GetTVChannelCollectionOnly();
        }

        public MCChannelInfoCollection GetMCChannels()
        {
            return this._myMCData.MCChannels;
        }
    }
}
